Agile Web Development with Rails 5.1 by Sam Ruby
Author:Sam Ruby
Language: eng
Format: epub
Tags: Pragmatic Bookshelf
Publisher: Pragmatic Bookshelf
In the preceding section, we created a plain-text email. The view file for our received action was called received.text.erb. This is the standard Rails naming convention. We can also create HTML-formatted emails.
Let’s try this with the order-shipped notification. We don’t need to modify any code—we simply need to create a new template:
rails51/depot_qa/app/views/order_mailer/shipped.html.erb
<h3>Pragmatic Order Shipped</h3>
<p>
This is just to let you know that we've shipped your recent order:
</p>
<table>
<tr><th colspan="2">Qty</th><th>Description</th></tr>
<%= render @order.line_items -%>
</table>
We don’t need to modify the partial, because the existing one will do just fine:
rails51/depot_qa/app/views/line_items/_line_item.html.erb
<% if line_item == @current_item %>
<tr class="line-item-highlight">
<% else %>
<tr>
<% end %>
<td class="quantity"><%= line_item.quantity %></td>
<td><%= line_item.product.title %></td>
<td class="price"><%= number_to_currency(line_item.total_price) %></td>
</tr>
But for email templates, Rails provides a bit more naming magic. If you create multiple templates with the same name but with different content types embedded in their filenames, Rails will send all of them in one email, arranging the content so that the email client can distinguish each.
This means you’ll want to either update or delete the plain-text template that Rails provided for the shipped notifier.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
The Mikado Method by Ola Ellnestam Daniel Brolund(11877)
Hello! Python by Anthony Briggs(11791)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(11240)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(9832)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(9420)
Grails in Action by Glen Smith Peter Ledbrook(9165)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(8808)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(8594)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(8309)
Windows APT Warfare by Sheng-Hao Ma(7780)
Layered Design for Ruby on Rails Applications by Vladimir Dementyev(7487)
Blueprints Visual Scripting for Unreal Engine 5 - Third Edition by Marcos Romero & Brenden Sewell(7398)
Kotlin in Action by Dmitry Jemerov(7264)
Solidity Programming Essentials by Ritesh Modi(4529)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(4412)
WordPress Plugin Development Cookbook by Yannick Lefebvre(4343)
Unity 3D Game Development by Anthony Davis & Travis Baptiste & Russell Craig & Ryan Stunkel(4240)
The Ultimate iOS Interview Playbook by Avi Tsadok(4217)
Functional Programming in JavaScript by Mantyla Dan(4216)